package com.community_cloud.server.servlets;

import java.io.IOException;

import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.SessionContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.user_hosted_storage.server.bl.CustomersManagerRemote;

/**
 * Servlet implementation class CustomersServlet
 */
@WebServlet("/servlet/client/private/CustomersServlet")
public class CustomersServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	@EJB
	private CustomersManagerRemote customersManagerRemote;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CustomersServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		if(action.equals("updateIP")) {
			customersManagerRemote.updateIP(request.getRemoteAddr());
		} else if(action.equals("updateAcceptPort")){
			int port = Integer.valueOf(request.getParameter("port"));
			customersManagerRemote.updateAcceptPort(port);
		} else if(action.equals("updateConnectPort")){
			int port = Integer.valueOf(request.getParameter("port"));
			customersManagerRemote.updateConnectPort(port);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
